package leetcode;

public class 中心下标 {
    // 暴力法
    public static int central_index(int[] nums) {
        int total = 0;
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            total+=nums[i];
        }

        for (int i = 0; i < nums.length; i++) {
            if (total-nums[i] == sum ) {
                return i;
            }
            else {
                sum+=nums[i];
                total -= nums[i];
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(central_index(new int[] {1, 7, 3, 6, 5, 6}));
    }
}
